package com.example.demo.controller;

import cn.hutool.v7.core.bean.BeanUtil;
import com.example.demo.dto.SiteDto;
import com.example.demo.model.Site;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;

@Controller
@Slf4j
public class DemoController {
  @Mapping("/get")
  @Get
  public Site get() {
    Site site = new Site();
    site.setName("demo");
    site.setCreateTime(LocalDateTime.now());
    return site;
  }

  @Mapping("/save")
  @Post
  public String save(@Body Site site) {
    log.info(site.toString());
    return site.getName();
  }

  @Mapping("/search")
  @Post
  public Site search(SiteDto siteDto) {
    return BeanUtil.copyProperties(siteDto, Site.class);
  }
}
